version 14.2
set more off

***************************************************************************************************************************
* THIS ROUTINE GENERATES FIGURES V OF WASEEM (2020) ROLE OF WITHHOLDING ... 
***************************************************************************************************************************

/* RAW TIME SERIES (WITHIN-FIRM CHANGES) MANUFACTURERS VS. IMPORTERS 1997-2003 */
*-------------------------------------------------------------------------------

use						"$project_data\STPAK_1996_2003_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						treat=business_sts=="1"
drop					if fy==1996
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
bys						period treat: g index=_n
bys						regnor period:egen output_ag=sum(output)
bys						regnor period:egen input_ag=sum(input)
local					var="domsale_ag"
g						logvar_real=log(`var')
qui						areg logvar_real i.period if treat==1, absorb(regnor)
g 						betahats=0
qui						sum period
local					nr=r(max)
forvalue				s=1/`nr' {
						cap replace betahats=_b[`s'.period] if period==`s' & treat==1
}
qui						areg logvar_real i.period if treat==0, absorb(regnor)
forvalue				s=1/`nr' {
						cap replace betahats=_b[`s'.period] if period==`s' & treat==0
}
#d						;
twoway  				(connected  betahats period if period>1 & index==1 & treat==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o))
						(connected  betahats period if period>1 & index==1 & treat==0,sort lwidth(thick) lcolor(midblue) mcolor(midblue) msymbol(o) lpattern(shortdash)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "97" 13 "98" 25 "99" 37 "00" 49 "01" 61 "02" 73 "03" 85 "04")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Within-firm Mean of Log Sales") ylabel(-2(1)2)
						xline(13 25 37, lpatter(dash) lcolor(green))
						legend(region(style(none)) label(1 "Manufacturers") label(2 "Importers"))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 					export "$project_output\PanelDD_lndomsale_UBP.eps", replace;
#d						cr

 /* DIFFERENCE-IN-DIFFERENCES MANUFACTURERS VS. IMPORTERS 1997-2003 */
*-------------------------------------------------------------------------------

use						"$project_data\STPAK_1996_2003_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					if fy==1996
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
bys						period regnor:egen amountpaid_ag=sum(amount_paid)
bys						regnor period:egen output_ag=sum(output)
bys						regnor period:egen input_ag=sum(input)
g						treat=business_sts=="1"
bys						period: g index=_n
qui						sum period
local					nr=r(max)
forvalues				s=1/`nr' {
g						pdum`s'=period==`s'
}
forvalues				s=1/`nr' {
g						treat_pdum`s'=treat*pdum`s'
}
local					var="domsale_ag"
g						logvar_real=log(`var')
qui						sum period
local					nr=r(max)
qui						areg logvar_real treat pdum2-pdum`nr' treat_pdum2-treat_pdum`nr', absorb(regnor) cluster(regnor)
g 						betahats=0
g						cil=0
g						cih=0
forvalue				s=1/`nr' {
						cap replace betahats=_b[treat_pdum`s'] if period==`s' 
						cap replace cil=_b[treat_pdum`s']-1.96*_se[treat_pdum`s'] if period==`s'
						cap replace cih=_b[treat_pdum`s']+1.96*_se[treat_pdum`s'] if period==`s'
}
#d						;
twoway  				(rarea cil cih period if period>1 & index==1,sort color(gs14))
						(connected  betahats period if period>1 & index==1,sort lwidth(thick) lcolor(red) mcolor(red) msymbol(o)),
						xtitle("Month of the Year") xscale(titlegap(*10))
						xlabel(1 "97" 13 "98" 25 "99" 37 "00" 49 "01" 61 "02" 73 "03" 85 "04")
						yscale(r(0))  yscale(titlegap(*10)) ytitle("Difference-in-differences Coefficient") ylabel(-2(1)2)
						xline(13 25 37, lpatter(dash) lcolor(green))
						legend(region(style(none)) label(1 "95% Confidence Interval") label(2 "Coefficient") order(2 1))
						graphregion(fcolor(white) style(none) color(white) margin(0 0 0 2)) bgcolor(white);
graph 					export "$project_output\DDP_`var'_UBP.eps", replace;
#d						cr
